import time

from selenium.webdriver.common.by import By

from base.page_base import BasePage


class BorrowMoney(BasePage):
    #元素定位
    click_borrow_01=(By.XPATH,'/html/body/div[1]/div[1]/div[2]/div/ul/li[3]/a')
    click_bo_02=(By.XPATH,'//*[@id="ng-app"]/body/div[2]/div/ul/li[1]/dl/dd[5]/a')
    input_name_03=(By.XPATH,'//*[@id="borrowPublish"]/div[3]/input')
    click_type_04=(By.XPATH,'//*[@id="borrowPublish"]/div[4]/select')
    input_money_05=(By.XPATH,'//*[@id="borrowPublish"]/div[5]/input')
    input_rate_06=(By.XPATH,'//*[@id="borrowPublish"]/div[6]/input')
    click_way_07 =(By.XPATH,'//*[@id="borrowPublish"]/div[8]/select')
    click_deadline_08=(By.XPATH,'//*[@id="borrowPublish"]/div[9]/select')
    click_pool_09=(By.XPATH,'//*[@id="borrowPublish"]/div[10]/select')
    click_min_money_10=(By.XPATH,'//*[@id="tender_amount_min"]')
    click_max_money_11=(By.XPATH,'//*[@id="tender_amount_max"]')
    input_describe_12=(By.XPATH,'//*[@id="borrow_contents"]')
    input_code_13  =(By.XPATH,'//*[@id="borrowPublish"]/div[16]/input')
    click_submit_14=(By.XPATH,'/html/body/div[2]/div/div/form/div[17]/input')



    cut_account=(By.XPATH,'/html/body/div[1]/div[2]/div[2]/div[1]/a/em')
    click_me_bor=(By.XPATH,'//*[@id="mlayout"]/div[2]/div[2]/div[3]/div[2]/dl/dd[1]/a')
    click_state=(By.XPATH,'//*[@id="mlayout"]/div[2]/div[3]/div[2]/div[2]/table/tbody/tr/td[4]/span')
    #定义方法
    def click_borrow(self):
        """点击品质理财"""
        self.base_click(self.click_borrow_01)

    def click_bo(self):
        """点击立即借款"""
        self.base_click(self.click_bo_02)

    def input_name(self,name='测试账号'):
        """输入姓名"""
        self.base_input(self.input_name_03,name)


    def click_type(self):
        """借款用途"""
        self.base_select_list(self.click_type_04,'买车')
    def input_money(self,money):
        """输入金额"""
        self.base_input(self.input_money_05,money)

    def input_rate(self,rate='7.00'):
        """输入年利率"""
        self.base_input(self.input_rate_06,rate)
    def click_way(self):
        """选择还款方式"""
        self.base_select_list(self.click_way_07,'到期还本还息')

    def click_deadline(self):
        """选择借款期限"""
        self.base_select_list(self.click_deadline_08,'15个月')

    def click_pool(self):
        """选择筹标期限"""
        self.base_select_list(self.click_pool_09,'79天')

    def click_min_money(self):
        """选择最小金额"""
        self.base_select_list(self.click_min_money_10,'50元')

    def click_max_money(self):
        """选择最大金额"""
        self.base_select_list(self.click_max_money_11,'10000元')

    def input_describe(self,describe='测试需要123456'):
        """输入备注"""
        self.base_input(self.input_describe_12,describe)

    def input_code(self,code='8888'):
        """输入验证码"""
        self.base_input(self.input_code_13,code)

    def click_submit(self):
        """点击提交按钮"""
        self.base_click(self.click_submit_14)


    def bor_money(self,money,name='测试账号',rate='7.00',describe='测试需要123456',code='8888'):
        self.click_borrow()
        self.click_bo()
        self.input_name(name)
        self.click_type()
        self.input_money(money)
        self.input_rate(rate)
        self.click_way()
        self.click_deadline()
        self.click_pool()
        self.click_min_money()
        self.click_max_money()
        self.input_describe(describe)
        self.input_code(code)
        self.click_submit()
    def look_result(self):
        self.base_click(self.cut_account)
        self.base_click(self.click_me_bor)

    def ultimately_result(self):
        time.sleep(1)
        return self.fd_element(self.click_state).text








